<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>نوشته های فاطمه معمار</title><link>https://virgool.ir/feed/@fm.memar</link><description></description><language>fa</language><pubDate>2026-11-12 08:07:14</pubDate><image><url>https://virgool.ir/images/default-avatar.jpg</url><title>فاطمه معمار</title><link>https://virgool.ir/@fm.memar</link></image><item><title>@JvmStatic</title><link>https://virgool.ir/@fm.memar/jvmstatic-nlg2suoidqae</link><description>@JvmStaticIn Kotlin, the package-level functions are represented as static methods. Also, in Kotlin, you can make static methods for functions that are defined in some companion object or named object by using the @JvmStatic annotation. For example:// Kotlin&#xA;object Utils {&#xA;    fun doSomething() {&#xA;        // logic here&#xA;    }&#xA;}Now, calling from Kotlin// calling from Kotlin class&#xA;Utils.doSomething()But, when you call this from Java, you get a compilation error.// calling from Java class&#xA;Utils.doSomething(); // compilation errorYou will have to call like this from Java.// calling from Java class&#xA;Utils.INSTANCE.doSomething(); // works fineHow can we make it work without using the INSTANCE?The answer is JvmStatic.Our updated Kotlin code:// Kotlin&#xA;object Utils {&#xA;&#xA;    @JvmStatic&#xA;    fun doSomething() {&#xA;        // logic here&#xA;    }&#xA;}</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Fri, 27 May 2022 05:09:13 +0430</pubDate></item><item><title>Fragment instantiation using companion objects</title><link>https://virgool.ir/@fm.memar/fragment-instantiation-using-companion-objects-ipegwc02mhnv</link><description>We have to use a companion object to instantiate a fragment. Remember we have to use the newInstance() method to initialize a fragment because we cannot use the parameterized constructor for fragments.companion object {    private const val ARG_PARAM1 = &#34;param1&#34;    private const val ARG_PARAM2 = &#34;param2&#34;    @JvmStatic    fun newInstance(param1: String, param2: String) =        Fragment().apply {            arguments = Bundle().apply {                putString(ARG_PARAM1, param1)                putString(ARG_PARAM2, param2)            }        }}</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Fri, 27 May 2022 05:08:17 +0430</pubDate></item><item><title>Source organization</title><link>https://virgool.ir/@fm.memar/source-organization-psrcklcsi4sq</link><description>By default, new Kotlin files are saved in src/main/java/, which makes it easy to see both Kotlin and Java files in one location. If you&#39;d prefer to separate your Kotlin files from your Java files, you can put Kotlin files under src/main/kotlin/ instead. If you do this, then you also need to include this directory in your sourceSets configuration, as shown below:android {    sourceSets {        getByName(&#34;main&#34;) {            java.srcDir(&#34;src/main/kotlin&#34;)        }    }}NOTEadd it in gradle app</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Fri, 27 May 2022 04:55:55 +0430</pubDate></item><item><title>lateinit vs lazy</title><link>https://virgool.ir/@fm.memar/lateinit-vs-lazy-c6uzmydnccao</link><description>lateinit vs lazylateinit Use it with mutable variable[var]lateinit var name: String       //Allowed lateinit val name: String       //Not Allowedbecause it can&#39;t be compiled to a final field- Allowed with only non-nullable data typeslateinit var name: String       //Allowed&#xA;    lateinit var name: String?      //Not Allowed- It is a promise to compiler that the value will be initialized in future.NOTE: If you try to access lateinit variable without initializing it then it throws UnInitializedPropertyAccessException.-Lateinit does not allocate memory before initializing.-Lateinit cannot be used for non-primitive datatypes, i.e., Long and int.-If you want your property to be initialized from outside in a way probably unknown beforehand, use lateinit.-lateinit var can be initialized from anywhere the object is seen from, e.g. from inside a framework code, and multiple initialization scenarios are possible for different objects of a single class.-If you want your property to be initialized from outside in a way probably unknown beforehand, use lateinit.-lateinit is for external initialisation: when you need external stuff to initialise your value by calling a method.2)by lazy { ... }- Lazy initialization was designed to prevent unnecessary initialization of objects-  In the Lazy initialization, your variable will not be initialized unless you call/use it.- Your variable will not be initialized unless you use it.- It is initialized only once. Next time when you use it, you get the value from cache memory.- It is thread safe(It is initialized in the thread where it is used for the first time. Other threads use the same value stored in the cache).- The variable can only be val.- The variable can only be non-nullable.-by lazy { ... }, in turn, defines the only initializer for the property, which can be altered only by overriding the property in a subclass.-While lazy is when it only uses dependencies internal to your object.--NOTE“val” is used to define Immutable data. It’s evaluated only once at the time of definition.“var” is used to define Mutable data. It’s evaluated only once at the time of definition.“lazy val” is used to define Immutable data. It is evaluated only once when we access it for first time. That means it is evaluated Lazily.</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Fri, 27 May 2022 04:51:36 +0430</pubDate></item><item><title>ایجاد dialog در اندروید استدیو</title><link>https://virgool.ir/@fm.memar/ایجاد-dialog-در-اندروید-استدیو-bs8g0tmkdjoy</link><description>در ابتدا یک layout برای dialog ایجاد کرده به نام dialog و سپس استایل های مد نظر را در style قرار می دهیم :&lt;style name=&#34;AlertDialog&#34;&gt;    &lt;item name=&#34;android:windowIsFloating&#34;&gt;true&lt;/item&gt;    &lt;item name=&#34;android:backgroundDimEnabled&#34;&gt;false&lt;/item&gt;    &lt;item name=&#34;windowMinWidthMajor&#34;&gt;85%&lt;/item&gt;    &lt;item name=&#34;windowMinWidthMinor&#34;&gt;85%&lt;/item&gt;     &lt;item name=&#34;android:windowFrame&#34;&gt;@null&lt;/item&gt;    &lt;item name=&#34;android:windowBackground&#34;&gt;@android:color/transparent&lt;/item&gt;    &lt;item name=&#34;android:windowContentOverlay&#34;&gt;@null&lt;/item&gt;    &lt;item name=&#34;android:windowTitleStyle&#34;&gt;@null&lt;/item&gt;    &lt;item name=&#34;android:windowAnimationStyle&#34;&gt;@android:style/Animation.Dialog&lt;/item&gt;    &lt;item name=&#34;android:windowSoftInputMode&#34;&gt;stateUnspecified|adjustPan&lt;/item&gt;    &lt;item name=&#34;android:background&#34;&gt;@android:color/transparent&lt;/item&gt;&lt;/style&gt;و در آخر :AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialog);View dialogLayout = LayoutInflater.from(this).inflate(R.layout.dialog,null);((TextView)dialogLayout.findViewById(R.id.messageAlert)).setText(message);builder.setView(dialogLayout);builder.show();</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Wed, 01 Jan 2020 13:35:09 +0330</pubDate></item><item><title>نوشتن و خواندن از دیتابیس Realm در اندروید استدیو (قسمت دوم)</title><link>https://virgool.ir/@fm.memar/نوشتن-و-خواندن-از-دیتابیس-realm-در-اندروید-استدیو-قسمت-دوم-o8wtg9mlcevf</link><description>در ابتدا یک instance ایجاد میکنیم این کارو می تونیم در onCreate انجام بدیمو همچنین می تونیم تنظیم کنیم که تا چه level ای برای ما log ایجاد کنه Realm mRealm = null;protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    mRealm = Realm.getDefaultInstance(); // opens &#34;myrealm.realm&#34;    RealmLog.setLevel(Log.VERBOSE);}حالا باید مدل دیتابیس رو ایجاد کرده و کلاس از RealmObject ارث بری کند.مثلا من در اینجا کلاس user ایجاد کردمpublic class User extends RealmObject {    @PrimaryKey    private int id;    private String userName;    // Standard getters &amp; setters generated by your IDE…    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getUserName() {        return userName;    }    public void setUserName(String phone) {        this.userName= userName;    }}حالا در mainActivity  یک user در دیتابیس اضافه کرده و آن query  را می خوانمنکته: به دلیل اینکه دیتابیس Realm به صورت خودکار id رو ایجاد نمی کند خودتان Id  رو ایجاد کنید:Number currentIdNum = .where(User.class).max(&#34;id&#34;);int nextId = (currentIdNum == null) ? 1 : currentIdNum.intValue() + 1;//write User obj = new User();obj.setId(nextId);obj.setUserName(&#34;Ahmad&#34;);mRealm.beginTransaction();User  realmCode=mRealm.copyToRealm(obj);mRealm.commitTransaction();//readRealmQuery&lt;User &gt; query = mRealm.where(User.class);RealmResults&lt;User &gt; results = query.findAll();پس از انجام عملیات نوشتن در دیتابیس می توانید فایل realm ای که ایجاد گردیده را مشاهده کنید :View --&gt; Tool windows --&gt; Device File Explore --&gt; data--&gt;data--&gt; اسم پکیج پروژه --&gt; files--&gt;default.realm هم چنین با نصب realm از سایت : https://realm.io/products/realm-studio/ می توانید default.realm را در Realm studio باز کرده و رکوردی که اضافه کرده اید را  مشاهده کنید.</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Sat, 28 Dec 2019 17:49:26 +0330</pubDate></item><item><title>تنظیمات Realm در اندروید استدیو(قسمت اول)</title><link>https://virgool.ir/@fm.memar/تنظیمات-realm-در-اندروید-استدیوقسمت-اول-si9vxhbkdd6q</link><description>برای نصب Realm در اندروید استدیو ابتدا :buildscript {    repositories {        jcenter()    }    dependencies {        classpath &#34;io.realm:realm-gradle-plugin:6.0.2&#34;    }}به build.gradle اضافه می کنیمسپس در build.gradle  مربوط به appزیر apply plugin: &#39;com.android.application&#39; این را اضافه می کنیمapply plugin: &#39;realm-android&#39;کلاس MyApplication را ایجاد کردهpublic class MyApplication extends Application {    @Override    public void onCreate() {        super.onCreate();        Realm.init(this);        RealmConfiguration realmConfiguration =new RealmConfiguration.Builder()                .name(Realm.DEFAULT_REALM_NAME)                .schemaVersion(0)                .deleteRealmIfMigrationNeeded()                .build();        Realm.setDefaultConfiguration(realmConfiguration);    }}سپس آن را در Manifest می گذاریم&lt;application    android:name=&#34;.MyApplication&#34;   ............&gt;</description><category>فاطمه معمار</category><author>فاطمه معمار</author><pubDate>Sat, 28 Dec 2019 17:23:49 +0330</pubDate></item></channel></rss>